package com.ls.completable;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class Demo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //同步调用
        CompletableFuture<Void> completableFuture1 = CompletableFuture.runAsync(() -> {
           System.out.println(Thread.currentThread().getName() + " :");
        });
        completableFuture1.get();
        //异步调用
        CompletableFuture<Integer> completableFuture2 = CompletableFuture.supplyAsync(() -> {
            System.out.println(Thread.currentThread().getName() + " :");
            return 1024;
        });
        Integer integer = completableFuture2.whenComplete((a,b)->{
            System.out.println(a);
            System.out.println(b);
        }).get();

    }
}
